package mp.weixin.WXpublic.sendkefu;

import mp.weixin.WXpublic.BaseSendKefuMessage;
import org.codehaus.jackson.node.JsonNodeFactory;
import org.codehaus.jackson.node.ObjectNode;

public class SKFMusicEntity extends BaseSendKefuMessage {

    private String title;
    private String description;
    private String musicURL;
    private String hQMusicUrl;
    private String mediaId;
    private String thumbMediaId;
    private long msgId;

    public SKFMusicEntity(String openId, String title, String description, String musicURL, String hQMusicUrl, String mediaId, String thumbMediaId, long msgId) {
        super(openId);
        this.title = title;
        this.description = description;
        this.musicURL = musicURL;
        this.hQMusicUrl = hQMusicUrl;
        this.mediaId = mediaId;
        this.thumbMediaId = thumbMediaId;
        this.msgId = msgId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMusicURL() {
        return musicURL;
    }

    public void setMusicURL(String musicURL) {
        this.musicURL = musicURL;
    }

    public String getHQMusicUrl() {
        return hQMusicUrl;
    }

    public void setHQMusicUrl(String hQMusicUrl) {
        this.hQMusicUrl = hQMusicUrl;
    }

    public long getMsgId() {
        return msgId;
    }

    public void setMsgId(long msgId) {
        this.msgId = msgId;
    }

    public String getMediaId() {
        return mediaId;
    }

    public void setMediaId(String mediaId) {
        this.mediaId = mediaId;
    }

    public String getThumbMediaId() {
        return thumbMediaId;
    }

    public void setThumbMediaId(String thumbMediaId) {
        this.thumbMediaId = thumbMediaId;
    }

    @Override
    public String toWeiXinKefuMessageJsonString() {
        ObjectNode jsono = new ObjectNode(JsonNodeFactory.instance);
        ObjectNode music = new ObjectNode(JsonNodeFactory.instance);
        music.put("title", this.title);
        music.put("description", this.description);
        music.put("musicurl", this.musicURL);
        music.put("hqmusicurl", this.hQMusicUrl);
        music.put("thumb_media_id", this.thumbMediaId);

        jsono.put("touser", this.getToUser());
        jsono.put("msgtype", getMsgType().getType());
        jsono.put(getMsgType().getType(), music);
        if (getKfAccount() != null && !getKfAccount().equals("")) {
            ObjectNode kf = new ObjectNode(JsonNodeFactory.instance);
            kf.put("kf_account", getKfAccount());
            jsono.put("customservice", kf);
        }
        return jsono.toString();
    }

    @Override
    public BaseSendKefuMessage.SendTypeEnum getMsgType() {
        return BaseSendKefuMessage.SendTypeEnum.MUSIC;
    }
}
